package com.service;

import java.util.ArrayList;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dao.OrderDao;
import com.hibernate.pojo.Order;
import com.hibernate.pojo.Shopcar;

@Service("orderService")
public class OrderService {
	
	@Resource(name="shopCarService")
	private ShopCarService scs;
	
	@Resource(name="orderDao")
	private OrderDao od;
	
	@Resource(name="order")
	private Order order;
	
	@Resource(name="userService")
	private UserServcie us;
	
	public boolean addOrder(String name,String address,double phone){
		ArrayList<Shopcar> scl = scs.getall(name);
		String content = "";
		for (Shopcar shopcar : scl) {
			content += "商品ID："+shopcar.getProductId()+"数量："+shopcar.getNumber()+";";
		}
		order.setAddress(address);
		order.setContent(content);
		order.setPhone(phone);
		order.setState("0");
		int userid = Integer.parseInt(us.getUserIdByName(name));
		order.setUserId(userid);
		return od.addOrder(order,userid);
	}
	
}
